package com.guchenbo.example.juc;

import java.util.concurrent.ExecutorService;
import java.util.concurrent.TimeUnit;

/**
 * @Author guchenbo
 * @Date 2018/10/30.
 */
public class ExecutorUtils {

    public static void stop(ExecutorService executorService) {
        stop(executorService, 1);
    }

    public static void stop(ExecutorService executorService, long second) {
        executorService.shutdown();
        try {
            if (!executorService.awaitTermination(second, TimeUnit.SECONDS)) {
                System.out.println("termination fail");
                executorService.shutdownNow();
            }
        } catch (InterruptedException e) {
            e.printStackTrace();
            executorService.shutdownNow();
        }
    }
}
